function SaleTarget_Code(){
	var buffer = new StringBuffer();
	var left=(swidth-90)/4;
	buffer.append('<div id="saletarget" class="saletarget">');
		buffer.append('<div class="titles"><div id="thisyear" class="jidu" val="" money="">第<font id="thisquarter">1</font>季度销售目标</div><div class="shuo"><div class="line"><div class="tu1"></div><div class="zi">目标金额</div></div><div class="line"><div class="tu2"></div><div class="zi">完成金额</div></div></div></div>');
		buffer.append('<div class="report"><div id="zhu1" val="" money="" class="zhu" style="margin-left:'+left+'px;"><div class="target"></div><div class="finish"></div></div><div id="zhu2" val="" money="" class="zhu" style="margin-left:'+left+'px;"><div class="target"></div><div class="finish"></div></div><div id="zhu3" val="" money="" class="zhu" style="margin-left:'+left+'px;"><div class="target"></div><div class="finish"></div></div></div>');
		buffer.append('<div class="rline"></div>');
		buffer.append('<div class="month"><div id="mh1" class="mh" style="margin-left:'+(left-5)+'px;">1月</div><div id="mh2" class="mh" style="margin-left:'+(left-10)+'px;">2月</div><div id="mh3" class="mh" style="margin-left:'+(left-10)+'px;">3月</div></div>');
		buffer.append('<div class="thismonth" style="padding-left:'+(left-5)+'px;"><div class="thismonthfinish">本月完成金额：<font id="thismoneyfinish" class="greens"></font></div><div class="thismonthtarget">本月目标金额：<font id="thismonthtarget" class="greens"></font></div><div class="thisquartertarget">本季目标金额：<font id="thisquartertarget" class="greens"></font></div></div>');
	buffer.append('</div>');
	return buffer.toString();
};

function Init_SaleTarget(){
	var data = {};
	data.act = "Find_SaleTarget";
	data.source=source;
	data.userid=userid;
	data.comid=comid;
	data.sign=GetSign(data.act);
	
	mui.getJSON(crm_domain, data, function (json) {
		if (json.state) {
	       $("#thisquarter").html(json.data.quarter);
	       $("#thisyear").attr("val",json.data.year);
	       var count=1;
	       $.each(json.data.list, function(i,info) {
	       		
	       		if(info.Type==1)
	       		{
	       			if(json.data.maxmoney>0)
	       			{
	       				var targetmoney=parseFloat(info.Money/json.data.maxmoney)*200;
	       				$("#zhu"+count+" .target").css("height",targetmoney+"px").html("<font style='position:absolute; top:-20px; width:100px; left:-35px; font-size:12px; color:#a9a9a9; text-align:center;'>"+info.Money+"</font>");
	       				var finishmoney=parseFloat(info.FinishMoney/json.data.maxmoney)*200;
	       				$("#zhu"+count+" .finish").css("height",(finishmoney>targetmoney?targetmoney:finishmoney)+"px"); 
	       			}
	       			if(info.Month==json.data.month)
	       			{
	       				$("#thismoneyfinish").html(info.FinishMoney.toFixed(2));
	       				$("#thismonthtarget").html(info.Money.toFixed(2));
	       				$("#mh"+count).html("<font style='color:#CF2D28;font-weight:bold;'>"+info.Month+"月</font>");
	       			}else
	       			{
	       				$("#mh"+count).html(info.Month+"月");
	       			}
	       			$("#zhu"+count).attr("val",info.Month);
	       			$("#zhu"+count).attr("money",info.Money);
	       			count++;
	       		}
	       		if(info.Type==2){
	       			$("#thisquartertarget").html(info.Money.toFixed(2));
	       		}
	       		if(info.Type==3)
	       		{
	       			$("#thisyear").attr("money",info.Money);
	       		}
	       		$("#button2").css("color","#fff");
	       });
	    }
	});
};


function SaleTargetSet_Code(){
	var buffer = new StringBuffer();
	var month1_money=$("#zhu1").attr("money");
	var month2_money=$("#zhu2").attr("money");
	var month3_money=$("#zhu3").attr("money");
	var quarter_money=$("#thisquartertarget").html();
	var year_money=$("#thisyear").attr("money");
	var readonly1="", readonly2="", readonly3="", readonly4="", readonly5="";
	var tip1="",tip2="",tip3="",tip4="",tip5="";
	if(month1_money>0){readonly1="readonly='readonly'";tip1="不能修改";}
	if(month2_money>0){readonly2="readonly='readonly'";tip2="不能修改";}
	if(month3_money>0){readonly3="readonly='readonly'";tip3="不能修改";}
	if(quarter_money>0){readonly4="readonly='readonly'";tip4="不能修改";}
	if(year_money>0){readonly5="readonly='readonly'";tip5="不能修改";}
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">'+$("#mh1").html()+'份目标</div></div><div class="ctext" style="width:50%;"><input id="txt_month1" type="text" placeholder="输入'+RUndefined($("#mh1").html()).DHtml()+'份销售目标" value="'+(month1_money=="0"?"":month1_money)+'" '+readonly1+'/></div><div class="carrow" style="width:20%; font-size:12px; color:#a9a9a9; text-align:right; padding-right:10px;">'+tip1+'</div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">'+$("#mh2").html()+'份目标</div></div><div class="ctext" style="width:50%;"><input id="txt_month2" type="text" placeholder="输入'+RUndefined($("#mh2").html().DHtml()).DHtml()+'份销售目标" value="'+(month2_money=="0"?"":month2_money)+'" '+readonly2+'/></div><div class="carrow" style="width:20%; font-size:12px; color:#a9a9a9; text-align:right; padding-right:10px;">'+tip2+'</div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">'+$("#mh3").html()+'份目标</div></div><div class="ctext" style="width:50%;"><input id="txt_month3" type="text" placeholder="输入'+RUndefined($("#mh3").html().DHtml()).DHtml()+'份销售目标" value="'+(month3_money=="0"?"":month3_money)+'" '+readonly3+'/></div><div class="carrow" style="width:20%; font-size:12px; color:#a9a9a9; text-align:right; padding-right:10px;">'+tip3+'</div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">第'+$("#thisquarter").html()+'季目标</div></div><div class="ctext" style="width:50%;"><input id="txt_thisquarter" type="text" placeholder="输入第'+RUndefined($("#thisquarter").html()).DHtml()+'季度销售目标" value="'+(quarter_money=="0"?"":quarter_money)+'" '+readonly4+' onfocus="ScrollTop()"/></div><div class="carrow" style="width:20%; font-size:12px; color:#a9a9a9; text-align:right; padding-right:10px;">'+tip4+'</div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">'+$("#thisyear").attr("val")+'年目标</div></div><div class="ctext" style="width:50%;"><input id="txt_thisyear" type="text" placeholder="输入'+$("#thisyear").attr("val")+'年销售目标" value="'+(year_money=="0"?"":year_money)+'" '+readonly5+' onfocus="ScrollTop()"/></div><div class="carrow" style="width:20%; font-size:12px; color:#a9a9a9; text-align:right; padding-right:10px;">'+tip5+'</div></div>');
	return buffer.toString();
};

function Set_SaleTarget(){
	
	
	plus.nativeUI.confirm("设置成功后将不能再修改，您确定要设置吗？", function(event){
	if(event.index==1)
	{
		var data = {};
		data.act = "Set_SaleTarget";
		data.month1=$("#zhu1").attr("val");
		data.month2=$("#zhu2").attr("val");
		data.month3=$("#zhu3").attr("val");
		data.quarter=$("#thisquarter").html();
		data.year=$("#thisyear").attr("val");
		data.month1_value=$("#txt_month1").val();
		data.month2_value=$("#txt_month2").val();
		data.month3_value=$("#txt_month3").val();
		data.quarter_value=$("#txt_thisquarter").val();
		data.year_value=$("#txt_thisyear").val();
		data.source=source;
		data.userid=userid;
		data.comid=comid;
		data.sign=GetSign(data.act);
		
		mui.getJSON(crm_domain, data, function (json) {
			plus.nativeUI.toast(json.msg);
			if (json.state) {
				CloseWindow();
				Init_SaleTarget();
				FindCrmReport();
			}
		});				
	}
	},"提示", ["取消","确认"]); 
};
